<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="btn1" type="button" onclick="dianji(this)">dom的onclick属性</button>
<button id="btn2" type="button">JS中onclick属性</button>
<button id="btn3" type="button">JS中addEventListener</button>
<script>
    let btn1 = document.querySelector("#btn1");
    let btn2 = document.querySelector("#btn2");
    let btn3 = document.querySelector("#btn3");

    function dianji() {
        console.log(this.id);
    }

    btn2.onclick = dianji;
    btn3.addEventListener("click", dianji);
</script>
</body>
</html>